package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;


public class AddOperation implements IOperation{
    public void work(BookList bookList) {
        //获取当前书架上的图书数
        int sz = bookList.getBookSize();

        //判断书架是否满了
        if (sz == bookList.getBooks().length) {
            System.out.println("书架满了，放不下了！");
            return;
        }
        //没满就继续执行
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入需要新增图书的书名：");
        String name = scanner.nextLine();
        System.out.println("请输入需要新增图书的作者：");
        String author = scanner.nextLine();
        System.out.println("请输入需要新增图书的类型：");
        String type = scanner.nextLine();
        System.out.println("请输入需要新增图书的价格：");
        int price = scanner.nextInt();

        //新增的图书
        Book book = new Book(name,author,price,type);

        //将新增的图书放到书架上
        bookList.setBooks(sz,book);

        //令书本数+1
        bookList.setBookSize(sz+1);
        return;
    }
}
